/*
 * Copyright (c) 2022 Huawei Device Co., Ltd.
 * Licensed under the Apache License,Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import {DeviceCommandModel} from '../models/deviceCommandModel';

const TAG = 'controlPageUtils'

export default class controlPageUtils {

  // 获取 JSON key 值
  static getKeyValue( data:string, ...args) {
    let jsonObject = JSON.parse(data);
    let properties = jsonObject.services[0].properties;
    let arr = []
    for( var i = 0; i < args.length; i++) {
      let key = args[i]
      arr[i] =  properties[key]
    }
    return arr;
  }

  /**
     * 获取智能加湿器阈值设置
     *
     * @return Command
     */
  static getHumidityThresholdCommand(humidityHig:number):DeviceCommandModel {
    let param = {}
    param["HumidityHig"] = humidityHig;
    return new DeviceCommandModel("SetHumidityThreshold", "SmartHumidifier", JSON.stringify(param));
  }


  /**
     * 获取智能加湿器打开命令
     *
     * @return Command
     */
  static getHumidifierStatusCommand(isOn:boolean):DeviceCommandModel {
    let param = {}
    if(isOn){
      param["HumidifierStatus"] = "ON";
    }
    else{
      param["HumidifierStatus"] = "OFF";
    }
    return new DeviceCommandModel("SetHumidifierStatus", "SmartHumidifier", JSON.stringify(param));
  }


  /**
     * 获取智能门铃响铃关闭命令
     *
     * @return Command
     */
  static getDoorbellCloseAlarmCommand():DeviceCommandModel {
    let param = {}
    param["Beep"] = "OFF";
    return new DeviceCommandModel("SetBeepStatus", "DoorBell", JSON.stringify(param));
  }


  /**
     * 获取智能门铃打开门命令
     *
     * @return Command
     */
  static  getDoorbellOpenCommand():DeviceCommandModel {
    let param = {}
    param["Lock"] = "ON";
    return new DeviceCommandModel("SetLock", "DoorBell", JSON.stringify(param));
  }

  /**
     * 获取可燃气体命令
     *
     * @return Command
     */
  static getCoalGasCommand() {
    let param = {}
    param["BeepStatus"] = "OFF";
    return new DeviceCommandModel("SetBeep", "GasDetection", JSON.stringify(param));
  }

}
